package com.shuaibiao.controller.base;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.shuaibiao.base.utils.captcha.CaptchaUtils;
/**
 * 
 * @author yin.jinbiao
 *
 */
@Controller
@RequestMapping
public class CaptchaController {
	
	 	@RequestMapping("/captcha")
	    public void generate(HttpServletRequest request, HttpServletResponse response){
	 		 response.setContentType("image/jpeg");
	 		 //禁止图像缓存       
	 		 response.setHeader("Pragma","no-cache");
	 		 response.setHeader("Cache-Control", "no-cache"); 
	 		 response.setDateHeader("Expires", 0);     
	 		 HttpSession session = request.getSession();  
	 		 CaptchaUtils captchaUtils = new CaptchaUtils(120, 40, 4,30); 
	 		 session.setAttribute("captcha", captchaUtils.getCode());      
	 		 try {
				captchaUtils.write(response.getOutputStream());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}    	 		
	    }
}
